package com.evl.api.payOrder.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.evl.api.payOrder.service.IPayTrainOrderService;
import com.evl.common.persistence.dao.TrainOrderMapper;
import com.evl.common.persistence.model.TrainOrder;
import com.evl.wxpay.util.paytype.PayType;
import com.evl.wxpay.util.paytype.WxPayApi;


@Service
public class PayTrainOrderService implements IPayTrainOrderService{
	
	@Resource
	private TrainOrderMapper orderMapper;

	@Override
	public Map order(String orderId,String formId) throws Exception{
		//调用位置下单接口
        Map<String, String> resoultMap = null;
        try{
        	TrainOrder order = orderMapper.selectById(orderId);
        	resoultMap = WxPayApi.Instance().request(order, PayType.ORDER.setFormId(formId));
        }catch (Exception e) {
        	e.printStackTrace();
        	throw new Exception("微信支付失败:["+e.getMessage()+"]");
		}
        return resoultMap;
	}

	@Override
	public Map refund(Map map,String formId) throws Exception{
		Map<String, String> resoultMap = null;
        try{
        	resoultMap = WxPayApi.Instance().request(map, PayType.REFUND.setFormId(formId));
        }catch (Exception e) {
        	throw new Exception("微信退款失败:["+e.getMessage()+"]");
		}
        return resoultMap;
	}
	
}
